﻿using IOA.MES.Client.Common;
using Seagull.BarTender.Print;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;

namespace IOA.MES.Client.NameplatePrinting
{
    /// <summary>
    /// PrinterSetting.xaml 的交互逻辑
    /// </summary>
    public partial class PrinterSetting : System.Windows.Window
    {
        public PrinterSetting()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var printers = new Printers();
            var dataSource = new List<string> { "" };
            foreach (Printer printer in printers)
            {
                dataSource.Add(printer.PrinterName);
            }
            cbBorderBarCodePrinter.ItemsSource = dataSource;
            cbNameplatePrinter.ItemsSource = dataSource;
            cbCurrentTagPrinter.ItemsSource = dataSource;
            cbEnergyTagPrinter.ItemsSource = dataSource;

            var borderBarCodePrinter = BaseEnv.GetStorage("边框条码");
            var nameplatePrinter = BaseEnv.GetStorage("铭牌");
            var currentTagPrinter = BaseEnv.GetStorage("电流标签");
            var energyTagPrinter = BaseEnv.GetStorage("能源标签");

            cbBorderBarCodePrinter.SelectedIndex = dataSource.IndexOf(borderBarCodePrinter);
            cbNameplatePrinter.SelectedIndex = dataSource.IndexOf(nameplatePrinter);
            cbCurrentTagPrinter.SelectedIndex = dataSource.IndexOf(currentTagPrinter);
            cbEnergyTagPrinter.SelectedIndex = dataSource.IndexOf(energyTagPrinter);
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var borderBarCodePrinter = Convert.ToString(cbBorderBarCodePrinter.SelectedValue);
            var nameplatePrinter = Convert.ToString(cbNameplatePrinter.SelectedValue);
            var currentTagPrinter = Convert.ToString(cbCurrentTagPrinter.SelectedValue);
            var energyTagPrinter = Convert.ToString(cbEnergyTagPrinter.SelectedValue);

            BaseEnv.SetStorage("边框条码", borderBarCodePrinter);
            BaseEnv.SetStorage("铭牌", nameplatePrinter);
            BaseEnv.SetStorage("电流标签", currentTagPrinter);
            BaseEnv.SetStorage("能源标签", energyTagPrinter);

            this.Close();
        }
    }
}
